<?php

namespace App\Models\Admin;


/**
 * @method where(string $string, int $int)
 */
class Member extends Base
{
    protected $table = 'member';

    protected $dateFormat = 'U';

    protected $guarded = [];

    public $timestamps = true;

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function subAccount()
    {
        return $this->hasMany(self::class,'pid','id');
    }

    public function info()
    {
        return $this->hasOne(MemberInfo::class,'user_id','id');
    }

    public function address()
    {
        return $this->hasOne(MemberAddress::class,'user_id','id');
    }

    public static function getMember($name='')
    {
        $uids = MemberInfo::where('code','like',"%$name%")->pluck('user_id');
        $select = self::orWhere('nickname','like',"%$name%")->orWhere('mobile','like',"%$name%");
        if (!empty($uids)){
            $select = $select->orWhereIn('id',$uids);
        }
        return $select->pluck('id');
    }
}
